$(function(){    
	layout();
	initFacebookAPI();
    $(window).resize(layout);
});

function layout() {
	var doc       = $(document);
	var docHeight = doc.height();
    
    var footer         = $('footer');
    var footerSize     = getSize(footer);
    var footerPosition = footer.position();
    
    var max = docHeight - footerSize.height - footerSize.padding.vertical;
    if (footerPosition.top < max) {
        footer.css('top', max);
    }
}

function initFacebookAPI() {
    (function(d, s, id) {
	    var js, fjs = d.getElementsByTagName(s)[0];
	    if (d.getElementById(id)) return;
	    js = d.createElement(s); js.id = id;
	    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
	    fjs.parentNode.insertBefore(js, fjs);
	}(document, 'script', 'facebook-jssdk'));
}


function getSize(element) {
	var padding = {
		top:    parseInt(element.css('padding-top')),
		right:  parseInt(element.css('padding-right')),
		bottom: parseInt(element.css('padding-bottom')),
		left:   parseInt(element.css('padding-left')),
        horizontal: 0,
        vertical: 0
	}
    padding.horizontal = padding.left + padding.right;
    padding.vertical   = padding.top + padding.bottom
	
	return {
		width:   element.width(),
		height:  element.height(),
		width2:  element.width() - padding.left - padding.right,
		height2: element.height() - padding.top - padding.bottom,
		padding: padding
	}
}

function fbShare() {
	var url = location.href;
	var win = window.open('https://www.facebook.com/sharer/sharer.php?u='+url, '_fb_share', 'width=400,height=300');
	win.focus(); 
}